﻿@{
    var tableName = PageViewModel.PageTableID(this);
    var tableToolBar = PageViewModel.PageTableToolbar(this);

    var dir_list_id = PageViewModel.ControlID(this, "dir_list");
    var editFunName = PageViewModel.PageFunctionName(this, "edit");
    var editDlgName = PageViewModel.PageEditDialog(this);
    var saveEditFunName = PageViewModel.PageFunctionName(this, "save_edit");

    var deleteFunName = PageViewModel.PageFunctionName(this, "delete");
    var refreshFunName = PageViewModel.PageFunctionName(this, "refresh");

}


<script type="text/javascript">
    function @editFunName (id) {
        var module = $("#@dir_list_id").datalist("getSelected");
        if (module != null) {
            var dlg = $dlg('@editDlgName');
            dlg.dialog({
                title: '编辑', width: 700, height: 450, closed: false, cache: false, modal: true, maximizable: false, resizable: false, maximized: false,
                href: '~/Systems/_EditAppDictionary?&ID=' + id,
                onResize: function () { $(this).dialog('center'); },
                buttons: [
                    {
                        text: "保 存",
                        handler: function () { @saveEditFunName (); },
                        iconCls: "icon-save"
                    }, {
                        text: "取 消",
                        handler: function () { $("#@editDlgName").dialog("close"); },
                        iconCls: "icon-cancel"
                    }
                ],
                onLoad: function () {
                    LoadObject(id, "~/Systems/GetAppDictionaryByID/", function (item) {
                        var form = $("#@editDlgName").find("form");
                        form.form("load", item);
                    });
                }
            });
        } else {
            $.messager.alert('提示', '请先选择模块', 'info');
        }
    }

    function @saveEditFunName () {
        var form = $("#@editDlgName").find("form");
        if (form.form('enableValidation').form('validate')) {
            var item = form.form_to_json();
            var module = $("#@dir_list_id").datalist("getSelected");
            item.TypeCode = module.Code;

            $.ajax({
                url: "~/Systems/SaveAppDictionary",
                type: "POST",
                data: item,
                success: function (e) {
                    if (e.Result) {
                        $.messager.alert('保存成功', '保存成功!', 'info', function () {
                            $('#@editDlgName').dialog('close');
                            @refreshFunName ();
                        });
                    } else {
                        $.messager.alert('保存失败', '保存失败: ' + e.Msg, 'error');
                    }
                },
                error: function (e) {
                    ShowAjaxError(e);
                }
            });
        }
    }

    function @refreshFunName () {
        var module = $("#@dir_list_id").datalist("getSelected");
        $.ajax({
            url: "~/Systems/GetAppDictionarys?typeCode=" + module.Code,
            type: "GET",
            success: function (e) {
                $("#@tableName").datagrid("loadData", e);
            },
            error: function (e) {
                ShowAjaxError(e);
            }
        });
    }
</script>

<script type="text/javascript">
    function @deleteFunName (id){
        if (id > 0 && confirm("确认删除配置信息?")) {
            $.ajax({
                async: false,
                method: "DELETE",
                url: $.Content("~/Systems/DeleteAppDictionary/" + id),
                context: $("#@tableName"),
                success: function (e) {
                    if (e.Result) {
                        @refreshFunName ();
                    } else {
                        $.messager.alert('删除数据', '删除失败: ' + e.Msg, 'error');
                    }
                },
                error: function (e1, e2, e3) {
                    ShowAjaxError(e1, "删除数据错误");
                }
            });
        }
    }
</script>

<table id="@tableName" class="easyui-datagrid" style="width:100%;" rownumbers="true" fit="true" fitcolumns="true"
       data-options="striped:true,border:false,toolbar:'#@tableToolBar'">
    <thead>
        <tr>
            <th data-options="field:'_edit',align:'center',formatter:function(v,r,i){
                                    return GridRowEditFmt('@editFunName', r.Id);
                            }" width="50">修改</th>
            <th data-options="field:'_remove',align:'center',formatter:function(v,r,i){
                                    return GridRowDeleteFmt('@deleteFunName', r.Id);
                            }" width="50">删除</th>
            <th data-options="field:'DictionaryID',align:'center'" width="80">编号</th>
            <th data-options="field:'Code'" width="100">编码</th>
            <th data-options="field:'Name'" width="180">名称</th>
            <th data-options="field:'Description'" width="200">说明</th>
            <th data-options="field:'Sequence',align:'center'" width="80">排序</th>
        </tr>
    </thead>
</table>
<div id="@tableToolBar" class="table-toolbar">
    <a href="javascript:@editFunName ()" class="easyui-linkbutton t-btn"><i class="fa fa-plus-circle" style="color:green"></i><span>新增</span></a>
</div>